<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>add() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>add()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>add()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/manipulating/add/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/03-manipulating/01-add.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().add(Number, String);
moment().add(Duration);
moment().add(Object);
</code></pre>

							</div>
<p>&#x901A;&#x8FC7;&#x589E;&#x52A0;&#x65F6;&#x95F4;&#x6765;&#x6539;&#x53D8;&#x539F;&#x59CB;&#x7684; moment&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x76F8;&#x5F53;&#x7A33;&#x5065;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x53EF;&#x4EE5;&#x4E3A;&#x73B0;&#x6709;&#x7684; moment &#x589E;&#x52A0;&#x65F6;&#x95F4;&#x3002;
&#x82E5;&#x8981;&#x589E;&#x52A0;&#x65F6;&#x95F4;&#xFF0C;&#x5219;&#x4F20;&#x5165;&#x8981;&#x589E;&#x52A0;&#x7684;&#x65F6;&#x95F4;&#x7684;&#x952E;&#x3001;&#x4EE5;&#x53CA;&#x8981;&#x589E;&#x52A0;&#x7684;&#x6570;&#x91CF;&#x3002;</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;);
</code></pre>
<p>&#x5982;&#x679C;&#x5BF9;&#x5E0C;&#x671B;&#x7B80;&#x77ED;&#xFF0C;&#x4E5F;&#x6709;&#x4E00;&#x4E9B;&#x5FEB;&#x6377;&#x7684;&#x952E;&#x3002;</p>
<pre><code class="language-javascript">moment().add(7, &apos;d&apos;);
</code></pre>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <th>&#x952E;</th>
      <th>&#x5FEB;&#x6377;&#x952E;</th>
    </tr>
    <tr>
      <td>years</td>
      <td>y</td>
    </tr>
    <tr>
      <td>quarters</td>
      <td>Q</td>
    </tr>
    <tr>
      <td>months</td>
      <td>M</td>
    </tr>
    <tr>
      <td>weeks</td>
      <td>w</td>
    </tr>
    <tr>
      <td>days</td>
      <td>d</td>
    </tr>
    <tr>
      <td>hours</td>
      <td>h</td>
    </tr>
    <tr>
      <td>minutes</td>
      <td>m</td>
    </tr>
    <tr>
      <td>seconds</td>
      <td>s</td>
    </tr>
    <tr>
      <td>milliseconds</td>
      <td>ms</td>
    </tr>
  </tbody>
</table>
<p>&#x5982;&#x679C;&#x8981;&#x540C;&#x65F6;&#x589E;&#x52A0;&#x591A;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x952E;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x4EEC;&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x4F20;&#x5165;&#x3002;</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;).add(1, &apos;months&apos;); // &#x94FE;&#x5F0F;
moment().add({days:7,months:1}); // &#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;
</code></pre>
<p>&#x6570;&#x91CF;&#x6CA1;&#x6709;&#x4E0A;&#x9650;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x91CD;&#x8F7D;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="language-javascript">moment().add(1000000, &apos;milliseconds&apos;); // &#x4E00;&#x767E;&#x4E07;&#x6BEB;&#x79D2;
moment().add(360, &apos;days&apos;); // 360 &#x5929;
</code></pre>
<h4>&#x6708;&#x4EFD;&#x548C;&#x5E74;&#x4EFD;&#x7684;&#x7279;&#x6B8A;&#x8003;&#x8651;</h4>
<p>&#x5982;&#x679C;&#x539F;&#x59CB;&#x65E5;&#x671F;&#x7684;&#x6708;&#x4EFD;&#x4E2D;&#x7684;&#x65E5;&#x671F;&#x5927;&#x4E8E;&#x6700;&#x7EC8;&#x6708;&#x4EFD;&#x4E2D;&#x7684;&#x5929;&#x6570;&#xFF0C;&#x5219;&#x8BE5;&#x6708;&#x4EFD;&#x4E2D;&#x7684;&#x65E5;&#x671F;&#x5C06;&#x4F1A;&#x66F4;&#x6539;&#x4E3A;&#x6700;&#x7EC8;&#x6708;&#x4EFD;&#x4E2D;&#x7684;&#x6700;&#x540E;&#x4E00;&#x5929;&#x3002;</p>
<pre><code class="language-javascript">moment([2010, 0, 31]);                  // &#x4E00;&#x6708; 31 &#x53F7;
moment([2010, 0, 31]).add(1, &apos;months&apos;); // &#x4E8C;&#x6708; 28 &#x53F7;
</code></pre>
<p>&#x5F53;&#x589E;&#x52A0;&#x8DE8;&#x8D8A;&#x590F;&#x65F6;&#x5236;&#x65F6;&#x95F4;&#x7684;&#x65F6;&#x95F4;&#x65F6;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x8BB0;&#x4F4F;&#x4E00;&#x4E9B;&#x7279;&#x6B8A;&#x7684;&#x6CE8;&#x610F;&#x4E8B;&#x9879;&#x3002;
&#x5982;&#x679C;&#x8981;&#x589E;&#x52A0;&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x5468;&#x3001;&#x6216;&#x5929;&#xFF0C;&#x5219;&#x539F;&#x59CB;&#x7684;&#x5C0F;&#x65F6;&#x5C06;&#x59CB;&#x7EC8;&#x4E0E;&#x589E;&#x52A0;&#x7684;&#x5C0F;&#x65F6;&#x5339;&#x914D;&#x3002;</p>
<p>&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x6708;&#x4F1A;&#x5C06;&#x6307;&#x5B9A;&#x7684;&#x6708;&#x6570;&#x589E;&#x52A0;&#x5230;&#x65E5;&#x671F;&#x3002;</p>
<pre><code class="language-javascript">moment([2010, 1, 28]);                 // &#x4E8C;&#x6708; 28 &#x53F7;
moment([2010, 1, 28]).add(1, &apos;month&apos;); // &#x4E09;&#x6708; 28 &#x53F7;
</code></pre>
<pre><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // &#x7F8E;&#x56FD;&#x590F;&#x4EE4;&#x65F6;&#x5F00;&#x59CB;&#x7684;&#x524D;&#x4E00;&#x5929;
m.hours(); // 5
m.add(1, &apos;days&apos;).hours(); // 5
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x589E;&#x52A0;&#x5C0F;&#x65F6;&#x3001;&#x5206;&#x949F;&#x3001;&#x79D2;&#x949F;&#x6216;&#x6BEB;&#x79D2;&#xFF0C;&#x5219;&#x4F1A;&#x5047;&#x8BBE;&#x671F;&#x671B;&#x7CBE;&#x786E;&#x5230;&#x5C0F;&#x65F6;&#xFF0C;&#x8FD9;&#x5C06;&#x4F1A;&#x5BFC;&#x81F4;&#x4E0D;&#x540C;&#x7684;&#x5C0F;&#x65F6;&#x3002;</p>
<pre><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // &#x7F8E;&#x56FD;&#x590F;&#x4EE4;&#x65F6;&#x5F00;&#x59CB;&#x7684;&#x524D;&#x4E00;&#x5929;
m.hours(); // 5
m.add(24, &apos;hours&apos;).hours(); // 6&#xFF08;&#x4F46;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x5148;&#x8BBE;&#x7F6E;&#x65F6;&#x533A;&#xFF09;
</code></pre>
<p>&#x53E6;&#x5916;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<a href="javascript:window.open('http://nodejs.cn/s/qDPC2g');" target="_blank" rel="nofollow">&#x65F6;&#x957F;</a>&#x6765;&#x589E;&#x52A0;&#x65F6;&#x95F4;&#x3002;</p>
<pre><code class="language-javascript">var duration = moment.duration({&apos;days&apos; : 1});
moment([2012, 0, 31]).add(duration); // &#x4E8C;&#x6708; 1 &#x53F7;
</code></pre>
<p>&#x5728; <strong>2.8.0</strong> &#x7248;&#x672C;&#x4E4B;&#x524D;&#xFF0C;&#x8FD8;&#x652F;&#x6301; <code>moment#add(String, Number)</code> &#x8BED;&#x6CD5;&#x3002;
&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x5B83;&#xFF0C;&#x800C;&#x4F7F;&#x7528; <code>moment#add(Number, String)</code>&#x3002;</p>
<pre><code class="language-javascript">moment().add(&apos;seconds&apos;, 1); // &#x5E9F;&#x5F03;&#x4E8E; 2.8.0
moment().add(1, &apos;seconds&apos;);
</code></pre>
<p>&#x4ECE; <strong>2.12.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x5F53;&#x4E3A;&#x65E5;&#x671F;&#x548C;&#x6708;&#x4EFD;&#x4F20;&#x5165;&#x5C0F;&#x6570;&#x65F6;&#xFF0C;&#x5B83;&#x4EEC;&#x4F1A;&#x88AB;&#x56DB;&#x820D;&#x4E94;&#x5165;&#x5230;&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x6574;&#x6570;&#x3002;
&#x661F;&#x671F;&#x3001;&#x5B63;&#x5EA6;&#x3001;&#x5E74;&#x4EFD;&#x4F1A;&#x88AB;&#x8F6C;&#x6362;&#x5230;&#x65E5;&#x671F;&#x6216;&#x6708;&#x4EFD;&#xFF0C;&#x7136;&#x540E;&#x56DB;&#x820D;&#x4E94;&#x5165;&#x5230;&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x6574;&#x6570;&#x3002;</p>
<pre><code class="language-javascript">moment().add(1.5, &apos;months&apos;) == moment().add(2, &apos;months&apos;)
moment().add(.7, &apos;years&apos;) == moment().add(8, &apos;months&apos;) //.7*12 = 8.4&#xFF0C;&#x53D6;&#x6574;&#x5230; 8
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().add(Number, String);
moment().add(Duration);
moment().add(Object);
</code></pre>

							</div>
<p>Mutates the original moment by adding time.</p>
<p>This is a pretty robust function for adding time to an existing moment. To add time, pass the key of what time you want to add, and the amount you want to add.</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;);
</code></pre>
<p>There are some shorthand keys as well if you&apos;re into that whole brevity thing.</p>
<pre><code class="language-javascript">moment().add(7, &apos;d&apos;);
</code></pre>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <th>Key</th>
      <th>Shorthand</th>
    </tr>
    <tr>
      <td>years</td>
      <td>y</td>
    </tr>
    <tr>
      <td>quarters</td>
      <td>Q</td>
    </tr>
    <tr>
      <td>months</td>
      <td>M</td>
    </tr>
    <tr>
      <td>weeks</td>
      <td>w</td>
    </tr>
    <tr>
      <td>days</td>
      <td>d</td>
    </tr>
    <tr>
      <td>hours</td>
      <td>h</td>
    </tr>
    <tr>
      <td>minutes</td>
      <td>m</td>
    </tr>
    <tr>
      <td>seconds</td>
      <td>s</td>
    </tr>
    <tr>
      <td>milliseconds</td>
      <td>ms</td>
    </tr>
  </tbody>
</table>
<p>If you want to add multiple different keys at the same time, you can pass them in as an object literal.</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;).add(1, &apos;months&apos;); // with chaining
moment().add({days:7,months:1}); // with object literal
</code></pre>
<p>There are no upper limits for the amounts, so you can overload any of the parameters.</p>
<pre><code class="language-javascript">moment().add(1000000, &apos;milliseconds&apos;); // a million milliseconds
moment().add(360, &apos;days&apos;); // 360 days
</code></pre>
<h4>Special considerations for months and years</h4>
<p>If the day of the month on the original date is greater than the number of days in the final month,
the day of the month will change to the last day in the final month.</p>
<pre><code class="language-javascript">moment([2010, 0, 31]);                  // January 31
moment([2010, 0, 31]).add(1, &apos;months&apos;); // February 28
</code></pre>
<p>There are also special considerations to keep in mind when adding time that crosses over daylight saving time.
If you are adding years, months, weeks, or days, the original hour will always match the added hour.</p>
<p>Adding a month will add the specified number of months to the date.</p>
<pre><code class="language-javascript">moment([2010, 1, 28]);                 // February 28
moment([2010, 1, 28]).add(1, &apos;month&apos;); // March 28
</code></pre>
<pre><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // the day before DST in the US
m.hours(); // 5
m.add(1, &apos;days&apos;).hours(); // 5
</code></pre>
<p>If you are adding hours, minutes, seconds, or milliseconds, the assumption is that you want precision to the hour, and will result in a different hour.</p>
<pre><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // the day before DST in the US
m.hours(); // 5
m.add(24, &apos;hours&apos;).hours(); // 6 (but you may have to set the timezone first)
</code></pre>
<p>Alternatively, you can use <a href="#/durations/" target="_blank" rel="nofollow">durations</a> to add to moments.</p>
<pre><code class="language-javascript">var duration = moment.duration({&apos;days&apos; : 1});
moment([2012, 0, 31]).add(duration); // February 1
</code></pre>
<p>Before version <strong>2.8.0</strong>, the <code>moment#add(String, Number)</code> syntax was also supported. It has been deprecated in favor of <code>moment#add(Number, String)</code>.</p>
<pre><code class="language-javascript">moment().add(&apos;seconds&apos;, 1); // Deprecated in 2.8.0
moment().add(1, &apos;seconds&apos;);
</code></pre>
<p>As of <strong>2.12.0</strong> when decimal values are passed for days and months, they are rounded to the nearest integer.
Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.</p>
<pre><code class="language-javascript">moment().add(1.5, &apos;months&apos;) == moment().add(2, &apos;months&apos;)
moment().add(.7, &apos;years&apos;) == moment().add(8, &apos;months&apos;) //.7*12 = 8.4, rounded to 8
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>